package juhouse.biz.kc.action;

import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import juhouse.biz.kc.dao.BasicDao;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class BasicAction extends DispatchAction  {	
	
	public ActionForward getBasicArray(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		String sPageSize=request.getParameter("PAGESIZE");
		String sCurrPage=request.getParameter("CURRPAGE");
		String SQL=request.getParameter("SQL");
		SQL=URLDecoder.decode(SQL, "UTF-8");
		String FIELDLIST=request.getParameter("FIELDLIST");
		BasicDao dao = new BasicDao();
		StringBuffer strlist = dao.getBasicArray(SQL,FIELDLIST,Integer.parseInt(sPageSize),Integer.parseInt(sCurrPage));
		response.setCharacterEncoding("GBK");
		request.setAttribute("validateResult", strlist.toString());
		return mapping.findForward("validateResult");
	}
	
	
	public ActionForward delBasic(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		String KEYVALUE=request.getParameter("KEYVALUE");
		String MASTERTABLENAME=request.getParameter("MASTERTABLENAME");
		String MASTERKEYFIELD=request.getParameter("MASTERKEYFIELD");

		
		BasicDao dao = new BasicDao();
		int  iResult = dao.delBasic(MASTERTABLENAME,MASTERKEYFIELD,KEYVALUE);
		response.setCharacterEncoding("GBK");
		request.setAttribute("validateResult", iResult);
		return mapping.findForward("validateResult");
	}

	public ActionForward delBasicGroup(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		String GroupTableName =request.getParameter("GroupTableName");
		String FInterId = request.getParameter("FInterId");
		if (FInterId==null) FInterId="";

		BasicDao dao = new BasicDao();
		int  iResult = dao.delBasicGroup(GroupTableName, FInterId);
		
		response.setCharacterEncoding("GBK");
		request.setAttribute("validateResult", iResult);
		return mapping.findForward("validateResult");
	}	
	
	
	public ActionForward saveBasicGroup(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		String GroupTableName =request.getParameter("GroupTableName");
		String GroupCodeField =request.getParameter("GroupCodeField");
		String GroupNameField =request.getParameter("GroupNameField");
		
		
		
		if (GroupNameField==null) GroupNameField="";
		
		String FGroupTypeField = request.getParameter("FGroupTypeField");
		String FInterId = request.getParameter("FInterId");
		if (FInterId==null) FInterId="";
		String FParentId = request.getParameter("FParentId");
		if (FParentId==null) FParentId="";
		String GroupCodeValue = request.getParameter("GroupCodeValue");
		if (GroupCodeValue==null) GroupCodeValue="";
		String GroupNameValue = request.getParameter("GroupNameValue");
		if (GroupNameValue==null) GroupNameValue="";
		GroupNameValue=URLDecoder.decode(GroupNameValue, "UTF-8");
		
		
		
		String GroupTypeValue=request.getParameter("GroupTypeValue");
		if (GroupTypeValue==null) GroupTypeValue="";
		
		BasicDao dao = new BasicDao();
		int  iResult = dao.saveBasicGroup(GroupCodeField, GroupNameField, FGroupTypeField, GroupTableName, FInterId, FParentId, GroupCodeValue, GroupNameValue,GroupTypeValue);
		
		response.setCharacterEncoding("GBK");
		request.setAttribute("validateResult", iResult);
		return mapping.findForward("validateResult");
	}
	
}
